<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2019/2/12
 * Time: 14:53
 * 监控   http websock 服务脚本
 */
class MonitorServer
{

    const PORT = 8080;

    public function server()
    {
        $shell = "netstat -anp | grep " . self::PORT . " | grep LISTEN | wc -l";
        $result = shell_exec($shell); //shell_exec这个函数被PHP禁止使用了 去php.ini开启
        if ($result >= 1) {
            // todo 发送 短信 邮寄  警报
            echo date('Y-m-d H:i:s').'success'.PHP_EOL;
        }else{
            echo date('Y-m-d H:i:s').'error'.PHP_EOL;
        }
    }
}

swoole_timer_tick(2000,function ($time_id){
    (new MonitorServer())->server();
});

